package org.oos.dao.impl;

import static org.oos.ApiUrlProvider.UserSites;

import org.oos.atom.ReviewFeed;
import org.oos.atom.entries.ReviewEntry;
import org.oos.atom.entries.impl.ReviewEntryImpl;
import org.oos.atom.impl.ReviewFeedImpl;
import org.oos.dao.UserSiteDao;
import org.oos.dao.lists.impl.FullAccessDynamicList;

import com.google.api.client.http.GenericUrl;

public class UserSiteDaoImpl extends
		AbstractDao<ReviewEntry, ReviewFeed<ReviewEntry>> implements UserSiteDao {

	private String userSlug;

	public UserSiteDaoImpl() {
		super(ReviewFeedImpl.class, ReviewEntryImpl.class);
	}

	@Override
	protected GenericUrl getEntryUrl(ReviewEntry entry) {
		return getEntryUrl(entry.getSlug());
	}

	@Override
	protected GenericUrl getEntryUrl(String param) {
		if (userSlug != null) {
			return UserSites.getUrl(userSlug, param);
		} else {
			throw new IllegalStateException("There must be a slug");
		}
	}

	@Override
	public GenericUrl getFeedUrl() {
		if (userSlug != null) {
			return UserSites.getUrl(userSlug);
		} else {
			throw new IllegalStateException("There must be a slug");
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	protected FullAccessDynamicList<ReviewEntry, ReviewFeed<ReviewEntry>> getList(ReviewFeed feed) {
		return new FullAccessDynamicList<ReviewEntry, ReviewFeed<ReviewEntry>>(this, feed);
	}

	@Override
	public void setUserSlug(String userSlug) {
		this.userSlug = userSlug;
	}

}
